<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增施工人员管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: jasny-bootstrap-css" />
    <th:block th:include="include :: bootstrap-fileinput-css" />
<!--     <script th:src="@{/js/plugins/dkq/jquery-1.12.4.js?v=3.6.1}"></script> -->
    <script th:src="@{/js/plugins/dkq/json2.js?v=3.6.1}"></script>
<!--     <script th:src="@{/js/jquery.min.js?v=3.6.1}"></script> -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <style>
		.file-preview {
		    padding: 0;
		    margin-bottom: 0;
		    border-radius: 0;
		    border: none;
		}
		
		.krajee-default.file-preview-frame {
		    margin-right: 20px;
		    padding: 0;
		    border: none;
		    box-shadow: none;
		}
		
		.krajee-default.file-preview-frame:not(.file-preview-error):hover {
		    border: none;
		    box-shadow: none;
		}
		
		.krajee-default .file-footer-caption {
			margin-bottom: 0;
		}
		
		.krajee-default.file-preview-frame .file-thumbnail-footer {
		    height: auto;
		}
		
		.krajee-default .file-caption-info {
			width: auto;
		}
		
		.kv-upload-progress .progress {
			margin-top: 0;
		}
		
		.krajee-default.file-preview-frame .kv-file-content,
		.krajee-default .file-size-info,
		.krajee-default .file-upload-indicator,
		.file-input .kv-file-upload,
		.file-input .kv-file-zoom {
			display: none;
		}
		
		.file-input .kv-file-remove {
			position: absolute;
			top: 3px;
			right: -15px;
			height: 14px;
			padding: 0;
			margin: 0;
			border: none;
			background: none;
		}
		
		.file-input .kv-file-remove:active, 
		.file-input .kv-file-remove:focus {
			background: none;
			outline: none;
			box-shadow: none;
		}
		
		.file-input .kv-file-remove .glyphicon-trash {
			color: red;
		}
		.submitBtn{
			display:block;margin:10px auto;
			width:50%;
			height:40px;
		}
		.submitBtn i{
			margin-right:3px;
			margin-left:-5px
		}
	</style>
    <style type="text/css">
        table label.error{position: inherit;}select + label.error{z-index:1;right:40px;}
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
    	<div class="text-left hidden-print">
	        <button class="btn btn-warning" onclick="readIdCard()"><i class="fa fa-edit"></i>读取身份证信息</button>
	        <button class="btn btn-warning" onclick="readBankCard()"><i class="fa fa-edit"></i>读取银行卡号</button>
	    </div>
        <form class="form-horizontal m" id="form-person-add">
        	<input id="photo" name="photo" type="hidden" >
            <div class="form-group">    
                <label class="col-sm-2 control-label is-required">姓名：</label>
                <div class="col-sm-4">
                    <input name="name" id="name" class="form-control" type="text" required>
                </div>
                <label class="col-sm-2 control-label is-required">性别：</label>
                <div class="col-sm-4">
                	<select name="sex" id="sex" class="form-control" th:with="type=${@dict.getType('sys_user_sex')}" required>
		                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
		            </select>
                </div>
            </div>
            <div class="form-group">  
            	<label class="col-sm-2 control-label is-required">身份证号：</label>
                <div class="col-sm-4">
                    <input name="card" id="card" class="form-control" type="text" required>
                </div>  
                <label class="col-sm-2 control-label is-required">联系电话：</label>
                <div class="col-sm-4">
                    <input name="phone" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
<!--                 <label class="col-sm-2 control-label ">联系地址：</label> -->
<!--                 <div class="col-sm-4"> -->
<!--                     <input name="address" id="address" class="form-control" type="text" > -->
<!--                 </div> -->
                <label class="col-sm-2 control-label ">所属班组：</label>
                <div class="col-sm-4">
                    <select name="suosbz" class="form-control" th:with="type=${@dict.getType('gys_banz')}" >
		                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
		            </select>
                </div>
                <label class="col-sm-2 control-label ">工种：</label>
                <div class="col-sm-4">
                    <select name="gongz" class="form-control" th:with="type=${@dict.getType('gys_gongz')}" >
		                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
		            </select>
                </div>
            </div>
            <div class="form-group">    
                
                <label class="col-sm-2 control-label is-required">开户银行：</label>
                <div class="col-sm-4">
                    <input name="khyh" class="form-control" type="text" required>
                </div>
                <label class="col-sm-2 control-label is-required">收款账号：</label>
                <div class="col-sm-4">
                    <input name="skzh" id="skzh" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                
                <label class="col-sm-2 control-label is-required">紧急联系人：</label>
                <div class="col-sm-4">
                    <input name="jinjlxr" class="form-control" type="text" required>
                </div>
                <label class="col-sm-2 control-label is-required">紧急联系人电话：</label>
                <div class="col-sm-4">
                    <input name="jinjlxrdh" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
            	<label class="col-sm-2 control-label">上传照片：</label>
                <div class="col-sm-10">
	            	<div class="file-loading">
		            	<input id="multipleFile" name="files" type="file" multiple>
		        	</div>
	            </div>
            </div>
            <div class="form-group"> 
            	<label class="col-sm-2 control-label is-required">健康承诺：</label>
                <div class="col-sm-10">
                	<label class="check-box">
                		<input type="checkbox" name="ishealth" value="1" required >
                		<b>
                		本人就身体健康做如下承诺：<br>
                		1、进入公司服务以前未患有以下疾病：(1)严重的身体疾病。(2)严重的精神疾病。(3)重大传染性疾病。<br>
                		2、如有严重的可能危及生命的病史，将如实上报给公司，不作任何隐瞒，以便公司根据实际情况安排工作。若因隐瞒病情在工作中遇到危及健康的事件发生，后果自负。
                		</b>
                	</label>
<!--                     <select name="ishealth" class="form-control" th:with="type=${@dict.getType('gys_ishealth')}" required> -->
<!-- 		                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option> -->
<!-- 		            </select> -->
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-12">
          	<button type="button" class="btn btn-sm btn-primary submitBtn" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <th:block th:include="include :: bootstrap-suggest-js" />
    <th:block th:include="include :: bootstrap-typeahead-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:inline="javascript">
        var prefix = ctx + "api"
        $("#form-person-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
//                 $.operate.saveTab(prefix + "/personadd", $('#form-person-add').serialize());
                $.operate.save(prefix + "/personadd", $('#form-person-add').serialize(), function(){
                    location.href = ctx + 'syssuccess';
                });
            }
        }
        
        $(document).ready(function () {
		       // 多图上传
		       $("#multipleFile").fileinput({
		           uploadUrl: "/gcgl/person/uploads",
		           uploadAsync: false,
		           showClose: false,
		           showCancel: false,
		           dropZoneEnabled: false,
		           buttonLabelClass: ''
		       }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
		       	var rsp = data.response;
//		       	   log.info("return urls：" + rsp.urls)
		           log.info("reutrn fileNames：" + rsp.fileNames)
//		           log.info("reutrn newFileNames：" + rsp.newFileNames)
//		           log.info("return originalFilenames：" + rsp.originalFilenames)
				   $("#photo").val(rsp.fileNames);
		       }).on('fileremoved', function (event, id, index) {
		           $("input[name='" + event.currentTarget.id + "']").val('')
		       })
		 });
        
        
        //--------------读卡器代码
        var httpUrl = "http://127.0.0.1:7846"
	    var wsUri ="ws://127.0.0.1:7846/ws"; 
	    var output;
	    var socket;
		var msgid = 0;
		var websocket_supported = false;
		var jsonp_supported = false;
		
		function readerInit(wzxx) {
			
			if( websocket_supported == false || socket.readyState == 2 || socket.readyState == 3) {
				websocket_supported = wsOpen();
			}
	
			if( ! jsonp_supported) {
				$.ajax({
					contentType:"application/json;charset=UTF-8",
					dataType: 'jsonp',
					timeout:10000,
					jsonp:"callback",
					url: httpUrl + "/getReaderInfo",
					success: function(resultInfo, status) {
						console.info("getReaderInfo ", resultInfo, status);
// 						$("#output").text(JSON.stringify(resultInfo));
						jsonp_supported = true;
					},
					complete: function(XMLHttpRequest, textStatus) {
						console.info("complete");
					},
					error: function(jqXHR, textStatus, errorThrown) {
						console.error("read card request error  ", textStatus, errorThrown );
// 						$("#output").text("read card error status: "+ textStatus+"<br>errorThrown: "  +errorThrown)
						jsonp_supported = false;
					}
				});
			}
		}
	
		$(document).ready(function(){
			 window.console = window.console || (function () {
				var c ={};
				c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile= c.clear = c.exception = c.trace = c.assert = function(){};
				return c;
			})();
			readerInit();
		});
	
		function parseCardInfo(text) {
			var result = {};
			
			result['race'] = ''
			result['type'] = text.substr(124, 1).trim();
	
			if (result['type'] == 'I') {
				//外国人永久居留证
				result['name'] = text.substr(0, 60).trim();
				result['gender'] = text.substr(60, 1).trim();
				result['IDNumber'] = text.substr(61, 15).trim();
				result['race'] = text.substr(76, 3).trim();
				result['cnName'] = text.substr(79, 15).trim();
				result['valied'] = text.substr(94, 8).trim();
				result['expire'] = text.substr(102, 8).trim();
				result['birthday'] = text.substr(110, 8).trim();
				result['version'] = text.substr(118, 2).trim();
				result['issuer'] = text.substr(120, 4).trim();
	
				result['address'] = "";
			}
			else {
				result['name'] = text.substr(0, 15).trim();
				result['gender'] = text.substr(15, 1).trim();
				result['race_id'] = text.substr(16, 2).trim();
				result['birthday'] = text.substr(18, 8).trim();
				result['address'] = text.substr(26, 35).trim();
				result['IDNumber'] = text.substr(61, 18).trim();
				result['issuer'] = text.substr(79, 15).trim();
				result['valied'] = text.substr(94, 8).trim();
				result['expire'] = text.substr(102, 8).trim();
	
				result['cnName'] = "";
				result['version'] = "";
			}
	
			if (result['type'] == 'J'){
				//港澳台居住证
				result['passNumber'] = text.substr(110, 9);
				result['issueCount'] = text.substr(119, 2);
			}
			else {
				result['passNumber'] = "";
				result['issueCount'] = "";
			}
	
			switch (result['gender']) {
// 				case '1': result['gender'] = '男'; break;
// 				case '2': result['gender'] = '女'; break;
				case '1': result['gender'] = '0'; break;
				case '2': result['gender'] = '1'; break;
				default: result['gender'] = '0';
			}
	
			switch (result['race_id']) {
				case '01': result['race'] = '汉'; break;
				case '02': result['race'] = '蒙古'; break;
				case '03': result['race'] = '回'; break;
				case '04': result['race'] = '藏'; break;
				case '05': result['race'] = '维吾尔'; break;
				case '06': result['race'] = '苗'; break;
				case '07': result['race'] = '彝'; break;
				case '08': result['race'] = '壮'; break;
				case '09': result['race'] = '布依'; break;
				case '10': result['race'] = '朝鲜'; break;
				case '11': result['race'] = '满'; break;
				case '12': result['race'] = '侗'; break;
				case '13': result['race'] = '瑶'; break;
				case '14': result['race'] = '白'; break;
				case '15': result['race'] = '土家'; break;
				case '16': result['race'] = '哈尼'; break;
				case '17': result['race'] = '哈萨克'; break;
				case '18': result['race'] = '傣'; break;
				case '19': result['race'] = '黎'; break;
				case '20': result['race'] = '傈僳'; break;
				case '21': result['race'] = '佤'; break;
				case '22': result['race'] = '畲'; break;
				case '23': result['race'] = '高山'; break;
				case '24': result['race'] = '拉祜'; break;
				case '25': result['race'] = '水'; break;
				case '26': result['race'] = '东乡'; break;
				case '27': result['race'] = '纳西'; break;
				case '28': result['race'] = '景颇'; break;
				case '29': result['race'] = '柯尔克孜'; break;
				case '30': result['race'] = '土'; break;
				case '31': result['race'] = '达翰尔'; break;
				case '32': result['race'] = '仫佬'; break;
				case '33': result['race'] = '羌'; break;
				case '34': result['race'] = '布朗'; break;
				case '35': result['race'] = '撒拉'; break;
				case '36': result['race'] = '毛南'; break;
				case '37': result['race'] = '仡佬'; break;
				case '38': result['race'] = '锡伯'; break;
				case '39': result['race'] = '阿昌'; break;
				case '40': result['race'] = '普米'; break;
				case '41': result['race'] = '塔吉克'; break;
				case '42': result['race'] = '怒'; break;
				case '43': result['race'] = '乌孜别克'; break;
				case '44': result['race'] = '俄罗斯'; break;
				case '45': result['race'] = '鄂温克'; break;
				case '46': result['race'] = '德昂'; break;
				case '47': result['race'] = '保安'; break;
				case '48': result['race'] = '裕固'; break;
				case '49': result['race'] = '京'; break;
				case '50': result['race'] = '塔塔尔'; break;
				case '51': result['race'] = '独龙'; break;
				case '52': result['race'] = '鄂伦春'; break;
				case '53': result['race'] = '赫哲'; break;
				case '54': result['race'] = '门巴'; break;
				case '55': result['race'] = '珞巴'; break;
				case '56': result['race'] = '基诺'; break;
				case '59': result['race'] = '穿青人'; break;
				case '60': result['race'] = '革家人'; break;
				case '97': result['race'] = '其它'; break;
				case '98': result['race'] = '入籍'; break;
				case '99': result['race'] = '其它'; break;
				default: break;
			}
			return result;
		}
	
	    function onWsOpen(evt) { 
	    }
	 
	    function onWsClose(evt) { 
	    }
	
	    function onWsMessage(evt) { 
			var jsondata = JSON.parse(evt.data);
			writeToScreen(evt.data); 
	
			if(jsondata.module == "idcard" && jsondata.function == "readcard" ) {
				
				if(jsondata.ret != 0) {
					//alert(jsondata.errorMsg);
					return ;
				}
	
				var	result = parseCardInfo(jsondata.data.text);
	
				$("#name").val(result.name);//姓名
				$("#sex").val(result.gender);//性别
				$("#address").val(result.address);
				$("#card").val(result.IDNumber);
				
				$("#photo").val(jsondata.data.photo);
			}
			else if(jsondata.module == "idcard" && jsondata.function == "getsam" ) {
				if(jsondata.ret != 0) {
					//alert(jsondata.errorMsg);
					return ;
				}
				$("#skzh").val(jsondata.data.samid);
			}
			else if(jsondata.module == "iccard" && jsondata.function == "getidsnr" ) {
				if(jsondata.ret != 0) {
					//alert(jsondata.errorMsg);
					return ;
				}
				$("#skzh").val(jsondata.data.idsnr);
			}
			else if(jsondata.module == "iccard" && jsondata.function == "pboc_read" ) {
				if(jsondata.ret != 0) {
					//alert(jsondata.errorMsg);
					return ;
				}
				$("#skzh").val(jsondata.data.number);
			}
			else if(jsondata.module == "idcard" && jsondata.function == "photo_verify_complete" ) {
				$("#photo").val(jsondata.data.camera_photo);
			}
			else {
			}
	    }
	 
	    function onWsError(evt) { 
	    }  
	 
	    function doSend(message) {
	        socket.send(message); 
	    }  
	 
	    function writeToScreen(message) { 
// 		    var pre = document.getElementById("output"); 
// 	        pre.style.wordWrap = "break-word";
// 			pre.innerHTML = message; 
	    }
		
		function wsOpen()
		{
			if(typeof(WebSocket) == "undefined"){
				return false;
			}
	
			socket = new WebSocket(wsUri); 
	        socket.onopen = function(evt) { 
	            onWsOpen(evt) 
	        }; 
	        socket.onclose = function(evt) { 
	            onWsClose(evt) 
	        }; 
	        socket.onmessage = function(evt) { 
	            onWsMessage(evt) 
	        }; 
	        socket.onerror = function(evt) { 
	            onWsError(evt) 
	        }; 
	
			return true;
		}
		
		function wsClose()
		{
			socket.close(); 
		}
	
	    function onJsopReadCard(resultInfo, status) {
			console.info("readIDCard ", resultInfo, status);
// 			$("#output").text(JSON.stringify(resultInfo));
			if( resultInfo.result === 0 ){
	
				var	result = parseCardInfo(resultInfo.wzInfo);
				$("#name").val(result.name);//姓名
				$("#sex").val(result.gender);//性别
				$("#address").val(result.address);//地址
				$("#card").val(result.IDNumber);//身份证
	
				$.ajax({
					contentType:"application/json;charset=UTF-8",
					dataType: 'jsonp',
					timeout:10000,
					jsonp:"callback",
					url:httpUrl +"/wltUnpack?wlt="+resultInfo.zpWlt+"&format=bmp",
					success:function(response){
						if(response['result'] === 0){
							var imageBase64 = response['image'];
							$("#photo").val(imageBase64);
						}else{
							alert("unpack error: " + response['result']);
						}
					},
					complete: function(XMLHttpRequest, textStatus) {
					}
				});
			}
			else {
				//alert(resultInfo.errorMsg);
			}
	
		}
	
	
		function getInfo()
		{
			msgid = msgid+1;
			doSend("{\"module\":\"common\",\"msgid\":\"" + msgid+  "\",\"function\":\"info\"}"); 
		}
	
		function readIdCard(){
			msgid = msgid+1;
			if(websocket_supported && socket.readyState == 1) {
				doSend("{\"module\":\"idcard\",\"msgid\":\"" + msgid+  "\",\"function\":\"readcard\"}"); 
			}
			else if(jsonp_supported) {
				$.ajax({
					contentType:"application/json;charset=UTF-8",
					dataType: 'jsonp',
					timeout:10000,
					jsonp:"callback",
					url: httpUrl + "/readIDCard",
					success: onJsopReadCard,
					complete: function(XMLHttpRequest, textStatus) {
						console.info("complete");
					},
					error: function(jqXHR, textStatus, errorThrown) {
						console.error("read card request error:  ", textStatus, errorThrown );
// 						$("#output").text("read card error status: "+ textStatus+"<br>errorThrown: "  +errorThrown);
						jsonp_supported = false;
					}
				});
			}
			else {
				alert("未检测到阅读器插件!");
			}
			
		}
	
		function readBankCard(){
			msgid = msgid+1;
			if(websocket_supported && socket.readyState == 1) {
				doSend("{\"module\":\"iccard\",\"msgid\":\"" + msgid+  "\",\"function\":\"pboc_read\"}"); 
			}
			else if(jsonp_supported) {
				$.ajax({
					contentType:"application/json;charset=UTF-8",
					dataType: 'jsonp',
					timeout:10000,
					jsonp:"callback",
					url: httpUrl + "/readBankCard",
					success: function(resultInfo, status) {
						console.info("readBankCard ", resultInfo, status);
// 						$("#output").text(JSON.stringify(resultInfo));
						if( resultInfo.result === 0 ){
							$("#skzh").val(resultInfo.number);
						}
					},
					complete: function(XMLHttpRequest, textStatus) {
						console.info("complete");
					},
					error: function(jqXHR, textStatus, errorThrown) {
						console.error("read card request error:  ", textStatus, errorThrown );
// 						$("#output").text("read card error status: "+ textStatus+"<br>errorThrown: "  +errorThrown);
						jsonp_supported = false;
					}
				});
			}
			else {
				alert("未检测到阅读器插件!");
			}
			
		}
	
    </script>
</body>
</html>